//
//  EvaluateViewController.m
//  FKGW
//
//  Created by song ce on 2017/4/18.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "EvaluateViewController.h"
#import "EValuateSuccessVC.h"
@interface EvaluateViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *goodImageView;
@property (weak, nonatomic) IBOutlet UILabel *placeHoderLabel;
@property (weak, nonatomic) IBOutlet UITextView *textView;

@property (weak, nonatomic) IBOutlet UIButton *haopingBtn;

@property (weak, nonatomic) IBOutlet UIButton *zhongpinBtn;
@property (weak, nonatomic) IBOutlet UIButton *chapingBtn;
@property(nonatomic,copy)NSString *evaluateLevel;
@end

@implementation EvaluateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.vcName = @"评价商品";
    self.textView.delegate = self;
    self.evaluateLevel = @"";

}
#pragma mark - UITextFiledDelegate
- (void)textViewDidChange:(UITextView *)textView;{
    
     if([self.textView.text isEqualToString:@""]){
        self.placeHoderLabel.hidden=NO;
    }else{
        self.placeHoderLabel.hidden=YES;
    }
}

//发表评论
//2.41进行评价接口
- (IBAction)commit:(UIButton *)sender {
    if([self.evaluateLevel isEqualToString:@""]){
        [MBProgressHUD showTipMessageInWindow:@"请选择评论等级"];
        return;
    }
    NSDictionary *paramDic = @{@"userId":USERID,
                               @"orderId":self.orderId,
                               @"evaluateContent":self.textView.text,
                               @"evaluateLevel":self.evaluateLevel,
                               @"productId":self.productId,
                               };
    [Tools AFNetworkingRequestTypePostWithUrl:EVALUATE paramters:paramDic afterResultBlock:^(NSDictionary *resultDic) {
        DLog(@"进行评价接口---%@",resultDic);
        if([resultDic[@"flag"] isEqualToString:@"true"]){
            NSDictionary *dataDic = resultDic[@"data"];
              if([dataDic isKindOfClass:[NSNull class]]) return ;
            if([dataDic[@"status"] isEqualToString:@"true"]){
                dispatch_async(dispatch_get_main_queue(), ^{
                    EValuateSuccessVC *es = [[EValuateSuccessVC alloc]init];
                    es.vcName = @"评价";
                    [self.navigationController pushViewController:es animated:YES];
                });
            }else{
                if(dataDic[@"errorString"]){
                    [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
                }
            }
        }else{
            if(resultDic[@"errorString"]){
                [MBProgressHUD showTipMessageInWindow:resultDic[@"errorString"]];
            }
        }
    }];
}


//好评
- (IBAction)haoping:(UIButton *)sender {
    [sender setTitleColor:[UIColor colorWithRed:0./255 green:216./255 blue:201./255 alpha:1.] forState:UIControlStateNormal];
    [sender setImage:[UIImage imageNamed:@"icon_haoping_sel"] forState:UIControlStateNormal];
    
    [self.zhongpinBtn setTitleColor:DEF_COLOR102 forState:UIControlStateNormal];
    [self.zhongpinBtn setImage:[UIImage imageNamed:@"icon_zhongping"] forState:UIControlStateNormal];
    
    [self.chapingBtn setTitleColor:DEF_COLOR102 forState:UIControlStateNormal];
    [self.chapingBtn setImage:[UIImage imageNamed:@"icon_chaping"] forState:UIControlStateNormal];

    self.evaluateLevel = @"0";
}
//中评
- (IBAction)zhongping:(UIButton *)sender {
    [sender setTitleColor:DEF_COLOR forState:UIControlStateNormal];
    [sender setImage:[UIImage imageNamed:@"icon_zhongping_sel"] forState:UIControlStateNormal];
    
    [self.haopingBtn setTitleColor:DEF_COLOR102 forState:UIControlStateNormal];
    [self.haopingBtn setImage:[UIImage imageNamed:@"icon_haoping"] forState:UIControlStateNormal];

    [self.chapingBtn setTitleColor:DEF_COLOR102 forState:UIControlStateNormal];
    [self.chapingBtn setImage:[UIImage imageNamed:@"icon_chaping"] forState:UIControlStateNormal];
   self.evaluateLevel = @"1";
}
//差评
- (IBAction)chaping:(id)sender {
    [sender setTitleColor:[UIColor colorWithRed:0./255 green:216./255 blue:201./255 alpha:1.] forState:UIControlStateNormal];
    [sender setImage:[UIImage imageNamed:@"icon_chaping_sel"] forState:UIControlStateNormal];
    
    [self.haopingBtn setTitleColor:DEF_COLOR102 forState:UIControlStateNormal];
    [self.haopingBtn setImage:[UIImage imageNamed:@"icon_haoping"] forState:UIControlStateNormal];
    
    [self.zhongpinBtn setTitleColor:DEF_COLOR102 forState:UIControlStateNormal];
    [self.zhongpinBtn setImage:[UIImage imageNamed:@"icon_zhongping"] forState:UIControlStateNormal];
    
   self.evaluateLevel = @"2";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
